const getters = {
  sidebar: state => state.app.sidebar,
  size: state => state.app.size,
  device: state => state.app.device,
  visitedViews: state => state.tagsView.visitedViews,
  cachedViews: state => state.tagsView.cachedViews,
  token: state => state.user.token,
  avatar: state => state.user.avatar,
  name: state => state.user.name,
  introduction: state => state.user.introduction,
  roles: state => state.user.roles,
  permissions: state => state.user.permissions,
  permission_routes: state => state.permission.routes,
  app_oid: state => state.permission.appOid,
  appList: state => state.permission.appList,
  login: state => {
    return JSON.parse(state.user.login || "{}");
  },
  skinClassname: state => state.user.skinClassname,
  userOid: state => state.user.userOid,
  friendList: state => {
    return parseData(state.imStore.friendList);
  },
  loginUser: state => {
    return parseData(state.imStore.loginUser);
  },
  conversationList: state => {
    return parseData(state.imStore.conversationList);
  },
  currentSessionContent: state => {
    return parseData(state.imStore.currentSessionContent);
  },
  historyUpdateFlag: state => {
    return parseData(state.imStore.historyUpdateFlag);
  },
  groupList: state => {
    return parseData(state.imStore.groupList);
  },
  currentVoiceVideoSessionContent: state => {
    return parseData(state.imStore.currentVoiceVideoSessionContent);
  },
  unReadCountTotal: state => {
    let cl = parseData(state.imStore.conversationList) || [];
    let count = 0;

    cl.forEach(ele => {
      if (ele.type !== "@TIM#SYSTEM") {
        count += ele.unreadCount || 0;
      }
    });

    return count;
  }
};

function parseData(dataString = "[]") {
  if (dataString && typeof dataString === "string") {
    return JSON.parse(dataString || "[]");
  }
  return JSON.parse("[]");
}
export default getters;
